package elephant.rpc;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 
 * @author skydu
 *
 */
public class DemoServiceImpl implements DemoService{
	//
	private static Logger logger=LoggerFactory.getLogger(DemoServiceImpl.class);
	//
	
	@Override
	public int echo(String msg) {
		logger.info("{}",msg);
		return 0;
	}
	
	@Override
	public User getUserById(int id) {
		User user=new User();
		user.id=id;
		user.name=id+"";
		user.createTime=new Date();
		return user;
	}
	
	@Override
	public List<User> getUsers() {
		List<User> list=new ArrayList<>();
		for(int i=0;i<10;i++){
			list.add(getUserById(i));
		}
		return list;
	}

	@Override
	public byte[] getFileContent(String id) throws IOException{
		File file=new File("/tmp/"+id+".jpg");
		byte[] images=Files.readAllBytes(file.toPath());
		logger.debug("getFileContent images length:{}",images.length);
		return images;
	}
}
